

#include "HeadIcon.h"

bool HeadIcon::init(){
    if(!TPanel::init()){
        return false;
    }
    panel=NULL;
    
    confPath=("proj/view/RoleHead.mxml");
    return true;
}



void  HeadIcon::procTuiEvent(const string&,TPanelItem*){
    
}


void  HeadIcon::initWidthConf(xml_node<> * pItem){
    TPanel::initWidthConf(pItem);
    
    int dir=readAttrInt(pItem, "dir");
    
    if(dir==2){
        panel=getPanel("rightPanel");
        getPanel("leftPanel")->setVisible(false);
    }else{ 
        panel=getPanel("leftPanel");
        getPanel("rightPanel")->setVisible(false);
    }
    showHead1();
    clearPanel();
}


void HeadIcon::setPockeNum(int num){
    if(getLabel("txtNum"))
    { 
        getLabel("txtNum")->setString(num);
    }
}

void HeadIcon::clearPanel(){
    if(!panel){
        return;
    }
    
   
    panel->getUI("noCallIcon")->setVisible(false);
    panel->getUI("passIcon")->setVisible(false);
    panel->getUI("call1Icon")->setVisible(false);
    panel->getUI("call2Icon")->setVisible(false);
    panel->getUI("call3Icon")->setVisible(false);
}
void HeadIcon::showCallNum(int i){
    clearPanel();
    
    if(i<=0){
        
        panel->getUI("noCallIcon")->setVisible(true);
        return;
    }
    char numName[50]={0};
    sprintf(numName, "call%dIcon",i);
    panel->getUI(numName)->setVisible(true);
}

void HeadIcon::showHead1(){
    
    getUI("head1")->setVisible(true);
    getUI("head2")->setVisible(false);
}
void HeadIcon::showHead2(){
    
    getUI("head1")->setVisible(false);
    getUI("head2")->setVisible(true);
}
void HeadIcon::showNoCall(){
    clearPanel();
    
    panel->getUI("noCallIcon")->setVisible(true);
    
}
void HeadIcon::showPass(){
    clearPanel();
    panel->getUI("passIcon")->setVisible(true);
    
    int passSound=getRandom(10, 39)/10;
    if(passSound==1){
        CSoundManager::sharedSoundManager()->playEffect("sounds/DDZPass1.wav");
    }else if(passSound==2){
        CSoundManager::sharedSoundManager()->playEffect("sounds/DDZPass2.wav");
    }else if(passSound==3){
        CSoundManager::sharedSoundManager()->playEffect("sounds/DDZPass3.wav");
    } 
}


void HeadIcon::onCreateComplete(){
}